package com.xrit.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xrit.constant.MessageConstant;
import com.xrit.pojo.SetMeal;
import com.xrit.result.Result;
import com.xrit.service.SetMealService;
import com.xrit.utils.QiNiuUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/setMealMobile")
public class SetMealMobileController {

    @Reference
    private SetMealService setMealService;

    /**
     * 套餐明细
     * @return
     */
    @RequestMapping("/findById")
    public Result findById(Integer id){
        //SetMeal meal = setMealService.findDetailsById(id);
        SetMeal meal = setMealService.findById(id);
        meal.setImg(QiNiuUtils.DOMAIN+meal.getImg());
        return new Result(true, MessageConstant.GET_SETMEAL_LIST_SUCCESS,meal);
    }

    @RequestMapping("/getAllSetMeal")
    public Result getAllSetMeal(){
        try{
            List<SetMeal> all = setMealService.findAll();
            all.forEach(s->{
                s.setImg(QiNiuUtils.DOMAIN+s.getImg());
            });
            return new Result(true, MessageConstant.GET_SETMEAL_LIST_SUCCESS,all);
        }catch (Exception e){
            e.printStackTrace();
        }
        return new Result(false, MessageConstant.GET_SETMEAL_LIST_FAIL);
    }
}
